package com.htt.app.bienbaogiaothong.menu;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;

import com.htt.app.bienbaogiaothong.R;
import com.htt.app.bienbaogiaothong.SearchActivity;

public class Menu {
	/*
	 *  start search activity
	 */
	public static void startSearch(Activity activity) {
		Intent intent = new Intent(activity, SearchActivity.class);
		activity.startActivity(intent);
	}
	
	/*
	 *  show alert dialog
	 *  when click button Ok, activity will be call function finish()
	 */
	public static void alertActivty(final Activity activity, String title, String message) {
		
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
		builder.setTitle(title);
		builder.setMessage(message);
		
		builder.setCancelable(true);
		builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				activity.finish();
			}
		}
		);
		
		builder.create();
		builder.show();
		
	}
	
	/*
	 * share app
	 */
	public static void share(final Activity activity) {
		
		String messageShare = "https://play.google.com/store/apps/details?id=" + activity.getApplicationContext().getPackageName();
		Intent shareIntent = new Intent(Intent.ACTION_SEND);
		shareIntent.setType("text/plain");
		shareIntent.putExtra(Intent.EXTRA_TEXT, messageShare);
		activity.startActivity(Intent.createChooser(shareIntent, 
				activity.getResources().getString(R.string.share_title)));
		
		/*
		Toast.makeText(activity, activity.getResources().getString(R.string.function_developing), 
				Toast.LENGTH_SHORT).show();
				*/
	}
	
	/*
	 * rating app
	 */
	public static void rateApp(final Activity activity) {
		/* This code assumes you are inside an activity */
		
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
		builder.setTitle(activity.getResources().getString(R.string.rate_app_title));
		builder.setMessage(activity.getResources().getString(R.string.rate_app_message));
		
		builder.setCancelable(true);
		builder.setPositiveButton(activity.getResources().getString(R.string.rate_app_title), new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				final Uri uri = Uri.parse("market://details?id=" + activity.getApplicationContext().getPackageName());
				final Intent rateAppIntent = new Intent(Intent.ACTION_VIEW, uri);

				if (activity.getPackageManager().queryIntentActivities(rateAppIntent, 0).size() > 0)
				{
				    activity.startActivity(rateAppIntent);
				}
				else
				{
				    Toast.makeText(activity, R.string.rate_app_error, Toast.LENGTH_SHORT).show();
				}
			}
		}
		
		);
		builder.setNegativeButton(activity.getResources().getString(R.string.rate_app_no), new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				
			}
		});
		
		builder.create();
		builder.show();
		/*
		Toast.makeText(activity, activity.getResources().getString(R.string.function_developing), 
				Toast.LENGTH_SHORT).show();
				*/
		
	}
	
}	
